/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agilelang.generate;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.agilelang.structure.AppConfig;
import org.agilelang.structure.FileStatic;

/**
 *
 * @author Roderick
 */
public final class CreateStructure {

    public CreateStructure(String arg_syntax) {
        /*
         Files
         - structure.xml
         - config.xml
         - syntax.xml
         - source.agile
         */
        //----------------------------------------------------------------------
        generateStructure();
        generateConfig();
        generateSyntax();
        generateSource();





        /*
         Folders
         tmpl
         out
         */
    }

    public void generateStructure() {
        AppConfig config = new AppConfig();
        List<FileStatic> files = new ArrayList<>();
        files.add(new FileStatic("style.css", "static/style.css"));
        //files.add(new FileStatic("index.php", "index.php"));
        config.file = files;
        //config.structure = "folder.zip";

        config.directory.add("model");
        config.directory.add("controller");
        config.directory.add("view");
        config.directory.add("static");

        generateFile(config, AppConfig.class, "structure.xml");
    }

    public void generateConfig() {
    }

    public void generateSyntax() {
    }

    public void generateSource() {
    }

    public void generateFile(Object obj, Class cls, String path) {
        JAXBContext jc = null;
        Marshaller marshaller;
        java.io.StringWriter sw = new StringWriter();
        try {
            jc = JAXBContext.newInstance(cls);
            marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(obj, sw);
        } catch (JAXBException ex) {
            System.out.println("Error --> " + ex.toString());
        }
        try {

            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(path)));
            pw.print(sw.toString());
            pw.close();
        } catch (IOException e) {
        }
    }
}
